import utils from './../utils'
import * as types from '../constants/order'
import store from 'store'



//从购物车中进行购买
export const buyByCart =(data,config={})=>{
	data= {...data,...{func:'buy-cart2'}}
    return (dispatch,getState)=>{
		return utils.form(utils.url.index,data)
		.then(res=>{
			config.callback && config.callback(res)
		})
	}
}
//立即购买
export const buyNow =(data,config={})=>{
	data= {...data,...{func:'buy-now'}}
    return (dispatch,getState)=>{
		return utils.form(utils.url.index,data)
		.then(res=>{
			config.callback && config.callback(res)
		})
	}
}

//获取买家订单列表
export const getOrderList =(data,callBack:()=>{})=>{
	data= {...data,...{func:'order-list'}}
	return utils.form(utils.url.index,data)
	.then(res=>{
		callBack && callBack(res)
	})
	
}
//订单详情
export const getOrderDetails =(data,callBack:()=>{})=>{
	data= {...data,...{func:'order-info'}}
	return (dispatch,getState)=>{
		return utils.form(utils.url.index,data)
		.then(res=>{
			return dispatch({type:types.GET_ORDER_INFO,data:res.data})
		})
	}
	
}

//paypal支付
export const ppPay =(data,config={})=>{
	data= {...data,...{func:'pp-pay'}}
    return (dispatch,getState)=>{
		return utils.form(utils.url.index,data)
		.then(res=>{
			
		})
	}
}

//订单列表当前状态
export const setOrderStatus =(data,config={})=>{
    return (dispatch,getState)=>{
		return dispatch({type:types.GET_ORDER_STATUS,data:data||0})
	}
}